package com.wyp168.renrenfilm.core.service.impl;

import com.github.pagehelper.PageInfo;
import com.github.pagehelper.page.PageMethod;
import com.wyp168.renrenfilm.core.dao.FilmLabelRelationDao;
import com.wyp168.renrenfilm.core.dao.HomeDao;
import com.wyp168.renrenfilm.core.entity.FilmLabelRelationEntity;
import com.wyp168.renrenfilm.core.entity.HomeEntity;
import com.wyp168.renrenfilm.core.service.FilmLabelRelationService;
import com.wyp168.renrenfilm.core.service.HomeService;
import com.wyp168.renrenfilm.core.vo.LabelRelationVO;
import com.wyp168.renrenfilm.core.vo.resp.LabelCountVO;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.Objects;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.wyp168.renrenfilm.core.dao.FilmLabelDao;
import com.wyp168.renrenfilm.core.entity.FilmLabelEntity;
import com.wyp168.renrenfilm.core.service.FilmLabelService;


@Service("filmLabelService")
public class FilmLabelServiceImpl extends ServiceImpl<FilmLabelDao, FilmLabelEntity> implements FilmLabelService {

    @Autowired
    HomeDao homeDao;

    @Autowired
    FilmLabelRelationDao relationDao;

    @Override
    public PageInfo<FilmLabelEntity> queryPage(Map<String, Object> params) {
        QueryWrapper<FilmLabelEntity> queryWrapper = new QueryWrapper<>();

        String labelName = (String) params.get("key");

        if (!StringUtils.isEmpty(labelName)) {
            queryWrapper.like("title", labelName);
        }

        int page = 1;
        int size = 10;

        if (!Objects.isNull(params.get("page"))) {
            page = Integer.parseInt((String) params.get("page"));
        }

        if (!Objects.isNull(params.get("limit"))) {
            size = Integer.parseInt((String) params.get("limit"));
        }

        PageMethod.startPage(page, size);

        List<FilmLabelEntity> filmLabelEntities = baseMapper.selectList(queryWrapper);
        return new PageInfo<FilmLabelEntity>(filmLabelEntities);
//        IPage<FilmLabelEntity> page = this.page(
//                new Query<FilmLabelEntity>().getPage(params),
//                new QueryWrapper<FilmLabelEntity>()
//        );
    }

    @Override
    public List<LabelCountVO> countData() {
        return relationDao.countLabelRelationData();
    }

}